package demo10.iterator.dinermergeri;

import java.util.Calendar;
import java.util.Iterator;

/**
 * 交流迭代器餐厅菜单
 * 使用java的迭代器
 * */
public class AlternatingDinerMenuIterator implements Iterator<Object> {
	MenuItem[] items;
	int position;//位置

	public AlternatingDinerMenuIterator(MenuItem[] items) {
		this.items = items;
		position = Calendar.DAY_OF_WEEK % 2;//Calendar.DAY_OF_WEEK 一周中的第几天  
	}
	@Override
	public Object next() {
		MenuItem menuItem = items[position];
		position = position + 2;
		return menuItem;
	}
	@Override
	public boolean hasNext() {
		if (position >= items.length || items[position] == null) {
			return false;
		} else {
			return true;
		}
	}
	@Override
	public void remove() {
		throw new UnsupportedOperationException(
			"餐馆的菜单交流迭代器不支持 remove()");
	}

}
